package com.zlk.algorithm.algorithm.unionAndFind;

import java.io.*;

// 并查集模版(牛客)
// 路径压缩 + 小挂大
// 测试链接 : https://www.nowcoder.com/practice/e7ed657974934a30b2010046536a5372
// 请同学们务必参考如下代码中关于输入、输出的处理
// 这是输入输出处理效率很高的写法
// 提交以下的code，提交时请把类名改成"Main"，可以直接通过
public class Code01_UnionFindNowCoder {


    //findFather(x) 查找x所在集合得代表集合   均摊优化
    //isSameSet(x,y) 是否是同一个集合
    //union(x,y) 合并两个集合
    //利用father数组 和size数组就可以实现

    public static int MAXN = 1000001;

    public static int[] father = new int[MAXN];

    public static int[] size = new int[MAXN];

    public static int[] stack = new int[MAXN];

    public static int n;


    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        while (in.nextToken() != StreamTokenizer.TT_EOF) {
            n = (int) in.nval;
            build();
            in.nextToken();
            int m = (int) in.nval;
            for (int i = 0; i < m; i++) {
                in.nextToken();
                int op = (int) in.nval;
                in.nextToken();
                int x = (int) in.nval;
                in.nextToken();
                int y = (int) in.nval;
                if(op==1){
                    out.println(isSameSet(x,y)?"Yes":"No");
                }else{
                    union(x,y);
                }
            }
        }
        out.flush();
        out.close();
        br.close();
    }

    private static void union(int x, int y) {
        int fx = findFather(x);
        int fy = findFather(y);
        if(fx==fy){
            return ;
        }
        int sizeFx = size[fx];
        int sizeFy = size[fx];
        if(sizeFx>=sizeFy){
            father[fy] =fx;
            size[fy]=-1;
            size[fx] = sizeFy+sizeFx;
        }else{
            father[fx] =fx;
            size[fx]=-1;
            size[fy] = sizeFy+sizeFx;
        }
    }

    private static boolean isSameSet(int x, int y) {
        return findFather(x) == findFather(y);
    }

    //扁平化
    private static int findFather(int cur) {
        int i = 0;
        //0 1 2
        //沿途收集的节点
        while (cur!=father[cur]){//   0     1
            stack[i++] = cur;// help[0]=0   help[1] = 1
            cur = father[cur];//cur=1     curr=2
        }
        i--;
        while (i>=0){
            //此处操作是为了平摊
            father[stack[i--]] = cur;
        }
        return cur;
    }

    private static void build() {
        for (int i = 0; i < n; i++) {
            father[i] = i;
            size[i]=1;
        }
    }
}
